<?php

m2import("phpinchains/util/db/DbEntityBase.php");

class WineryOrderFormCatEntity extends phpinchains_util_db_DbEntityBase {

    function WineryOrderFormCatEntity($actionform, phpinchains_util_db_Preprocessor $preprocessor = null, phpinchains_util_db_Postprocessor $postprocessor = null)
    {
        $af = new phpinchains_ActionForm();
        $this->table = base_ApplicationContext::getInstance()->getAccessFactory()->getConnection()->getTableprefix()."_wineryOrderFormCat";
        $this->fields = array(
            array('id', 'int'),
            array('wofcpos', 'int'),
            array('wofcname', 'string')
        );
        $this->defaultvalues = array (
        );
        $this->index = array (
        );
        $this->blobs = array (
        );
        $this->foreignKeys = array(

        );
        
        parent::phpinchains_util_db_DbEntityBase($af, $preprocessor, $postprocessor);
    }

    function moveUp ($id) {
        if ((int) $id) {
            $obj = $this->findByPrimaryKey($id, array('fields' => 'id,wofcpos'));
            $fields = array(array('wofcpos', $obj['wofcpos'], '<'));
            
            $prev = $this->findByFields($fields, 'AND', array('limit' => 1, 'orderby' => 'wofcpos desc', 'fields' => 'id,wofcpos'));
            if (count($prev)) {
                $prev[0]['wofcpos']++;
                $this->update($prev[0]);
                $obj['wofcpos']--;
                $this->update($obj);
            }
        }
    }

    function moveDown ($id) {
        if ((int) $id) {
            
            $obj = $this->findByPrimaryKey($id, array('fields' => 'id,wofcpos'));
            $fields = array(array('wofcpos', $obj['wofcpos'], '>'));
            
            $next = $this->findByFields($fields, 'AND', array('limit' => 1, 'orderby' => 'wofcpos', 'fields' => 'id,wofcpos'));
            if (count($next)) {
                $next[0]['wofcpos']--;
                $this->update($next[0]);
                $obj['wofcpos']++;
                $this->update($obj);
            }
        }
    }




}


?>